import os
import openai

# 需要输入一个openai官方提供的key秘钥
# 可以自行去官网生成这key

openai.api_key = "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"


def chatGPT(start_sequence: str) -> str:
    prompt = start_sequence
    try:
        response = openai.Completion.create(
            model = "text-davinci-003",
            prompt = prompt,
            temperature = 1,
            # 回答的文字长度
            max_tokens = 2000,
            frequency_penalty = 0,
            presence_penalty = 0
        )
        return response["choices"][0]["text"].strip()
    except Exception as e:
        return str(e)